
package huoye.shops;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentLocationListener;
import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.map.geolocation.TencentLocationRequest;


/**
 * Created by user on 2017/11/25.
 */


public class TestActivity extends AppCompatActivity implements TencentLocationListener {



    private TencentLocationManager mLocationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        Log.e("test===","注册");

        mLocationManager = TencentLocationManager.getInstance(this);

    }


    @Override
    public void onResume() {
        super.onResume();
        startLocation();
        Log.e("test===","resume");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.e("test===","start");
    }

    @Override
    protected void onPause() {
        super.onPause();
        stopLocation();
        Log.e("test===","注销");
    }


    @Override
    public void onLocationChanged(TencentLocation location, int error,
                                  String reason) {

        Log.e("location===","开始定位"+error+"?"+reason);

        if (error == TencentLocation.ERROR_OK) {
            // 更新 status
            Log.e("test===",location.getAddress());
            Log.e("test===",location.toString());
        }
    }

    @Override
    public void onStatusUpdate(String name, int status, String desc) {
        Log.e("location===","开始定位状态回调"+status+"?"+desc);
    }

    private void startLocation() {
        TencentLocationRequest request = TencentLocationRequest.create();
        request.setInterval(5000);
        mLocationManager.requestLocationUpdates(request, this);

    }

    private void stopLocation() {
        mLocationManager.removeUpdates(this);
    }






}
